<template>
	<view>
		<my-search @click="gotoSearch" bgColor="#c000000" :redius="15" placeholder="默认的placeholder值"  />
		<view class="scroll-view-container">
			<!-- //左侧滚动图区域 -->
			<scroll-view scroll-y="true" class="left-scroll-view" :style="{height: wh + 'px'}">
				<block v-for="(item,index) in cateList" :key="index">
					<view :class="['left-srcoll-view-item',index === active ? 'active' : '']" 
							@click="activeChanged(index)">{{item.cat_name}}</view>
				</block>
			</scroll-view>
			<!-- 右侧 -->
			<scroll-view scroll-y="true" :scroll-top="scrollTop" class="right-scroll-view" :style="{height: wh + 'px'}">
				<view class="cate-leve" v-for="(item,index) in cateLeve" :key="index">
					<view class="cate-leve-title">
						/{{item.cat_name}}/
					</view>
					<view class="cate-leves-list">
						<view class="cate-leves-item" v-for="(items,indexs) in item.children" :key="indexs"
							@click="gotoGoodsList(items)">
							<image :src="items.cat_icon" mode=""></image>
							<text>{{ items.cat_name }}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import  badgeMix  from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				wh:0,
				cateList:[],//分类的数据列表
				cateLeve:[],
				active:0,//当前选中的激活项，默认第一个被选中
				scrollTop:0
			};
		},
		onLoad(){
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight - 50
			this.getCateList()
		},
		methods:{
			async getCateList(){
				const { data:res } = await uni.$http.get('/api/public/v1/categories')
				console.log(res);
				if(res.meta.status !== 200) return uni.$showMsg()
				this.cateList = res.message
				this.cateLeve = res.message[0].children
			},
			activeChanged(index){
				this.active = index
				this.cateLeve = this.cateList[index].children
				this.scrollTop = this.scrollTop == 0 ? 1 : 0
			},
			gotoGoodsList(item){
				console.log(item);
				uni.navigateTo({
					url:`/subpkg/goods_list/goods_list?cid=${item.cat_id}`
				})
			},
			gotoSearch(){
				uni.navigateTo({
					url: '/subpkg/search/search'
				})
			}
		}	
	}
</script>

<style lang="scss">		
.scroll-view-container{
	display: flex;
	.left-scroll-view{
		width: 120px;
		.left-srcoll-view-item{
			line-height: 60px;
			background-color: #F7F7F7;
			text-align: center;
			font-size: 12px;
			&.active{
				background-color: #ffffff;
				position: relative;
				&::before{
					content: '';
					display: block;
					width: 3px;
					height: 30px;
					background-color: #c00000;
					position: absolute;
					top: 50%;
					left: 0;
					transform: translateY(-50%);
				}
			}
		}
	}
	.cate-leve-title{
		font-size: 12px;
		font-weight: bold;
		text-align: center;
		padding: 15px 0;
	}
	.cate-leves-list{
		display: flex;
		flex-wrap: wrap;
		.cate-leves-item{
			width: 33.33%;
			margin-bottom: 10px;
			display: flex;
			flex-direction: column;
			align-items: center;
			image{
				width: 60px;
				height: 60px;
			}
			text{
				font-size: 12px;
			}
		}
	}
}
</style>
